//
//  PopView.m
//  MindBox
//
//  Created by MS on 16-1-12.
//  Copyright (c) 2016年 Lemon. All rights reserved.
//

#import "PopView.h"

#import "UIImage+Image.h"
@interface PopView ()
@property (weak, nonatomic) IBOutlet NMRangeSlider *sliderView;

@property (weak, nonatomic) IBOutlet UIButton *finishBtn;



/**
 *  包邮选项
 */
@property (weak, nonatomic) IBOutlet UISwitch *freePock;
/**
 *  有货选项
 */
@property (weak, nonatomic) IBOutlet UISwitch *isGoods;
@end

@implementation PopView

+(instancetype)popViewWithXib
{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
}


-(void)awakeFromNib
{
    [self configureSliderView];
    _finishBtn.layer.cornerRadius = 5;
    _finishBtn.clipsToBounds = YES;
   
}



- (void) configureSliderView
{
    UIImage * image = nil;
   image = [UIImage imageWithColor:[UIColor redColor]];
    image = [UIImage image:image byScalingToSize:CGSizeMake(10, 1.5)];
    image  = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:0];
    _sliderView.trackImage = image;
    
    
    image =[UIImage imageWithColor:[UIColor lightGrayColor]];
    image = [UIImage image:image byScalingToSize:CGSizeMake(10, 1)];
    image  = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
    _sliderView.trackBackgroundImage = image;
    
    image = [UIImage imageNamed:@"slider-handle"];
     image = [UIImage image:image byScalingToSize:CGSizeMake(30, 30)];
    image = [image imageWithAlignmentRectInsets:UIEdgeInsetsMake(-1, 0, 1,10)];
    _sliderView.lowerHandleImageNormal = image;
    _sliderView.upperHandleImageNormal = image;
    
    [self resetValue];
}

-(void)resetValue
{
    self.sliderView.minimumValue = 0;
    self.sliderView.maximumValue = 1005;
    
    self.sliderView.lowerValue = 0;
    self.sliderView.upperValue = 1005;
    
    self.sliderView.minimumRange = 100;
    self.isGoods.on = NO;
    self.freePock.on = NO;
    
}

- (IBAction)sliderViewVauleChanged:(NMRangeSlider *)sender {
    
    
//    NSLog(@"%d--%d",(int)sender.lowerValue,(int)sender.upperValue);
    
}

- (IBAction)finishBtn:(id)sender {
    
    _hasGoods = _isGoods.on;
    _freePocks = _freePock.on;
    _lowerValue = _sliderView.lowerValue;
    _upValue = _sliderView.upperValue;
    
    if ([self.delegate respondsToSelector:@selector(popViewFnishBtnDidClick:)]) {
       
        [self.delegate popViewFnishBtnDidClick:self];
    }

}


@end
